package org.example.resourceplatform.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import java.time.LocalDateTime;

@Entity
@Table(name = "comment",
        indexes = {
                @Index(name = "idx_comment_user", columnList = "user_id"),
                @Index(name = "idx_comment_doc", columnList = "doc_id"),
                @Index(name = "idx_comment_time", columnList = "comment_time"),
                @Index(name = "idx_comment_is_deleted", columnList = "is_deleted")
        })
@Getter
@Setter
@NoArgsConstructor
public class Comment {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "comment_id")
    private Integer commentId;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "doc_id", nullable = false)
    private Document document;

    @Column(name = "comment_content", nullable = false, length = 500)
    private String content;

    @CreationTimestamp
    @Column(name = "comment_time", nullable = false, updatable = false)
    private LocalDateTime commentTime;

    @Column(name = "is_deleted", nullable = false)
    private Boolean deleted = false;

    public Comment(User user, Document document, String content) {
        this.user = user;
        this.document = document;
        this.content = content;
    }
}